const calculateWinner = function (squares) {
    if(!squares){
        return null
    }
    const lines = [
        [0, 1, 2],
        [3, 4, 5],
        [6, 7, 8],
        [0, 3, 6],
        [1, 4, 7],
        [2, 5, 8],
        [0, 4, 8],
        [2, 4, 6]
    ];
    for (let i = 0; i < lines.length; i++) {
        const [a, b, c] = lines[i];
        if (squares[a] && squares[a] === squares[b] && squares[a] === squares[c]) {
            return squares[a];
        }
    }
    return null;
}
function CalculateWinnerSquareArray(square) {
    if(!square){
        return []
    }
    const lines = [
        [0, 1, 2],
        [3, 4, 5],
        [6, 7, 8],
        [0, 3, 6],
        [1, 4, 7],
        [2, 5, 8],
        [0, 4, 8],
        [2, 4, 6],
    ];
    let result = []
    for (let i = 0; i < lines.length; i++) {
        const [a, b, c] = lines[i];
        if (square[a] && square[a] === square[b] && square[a] === square[c]) {
            result.push(a, b, c) 
        }
    }
    return result
}

const showColumnAndRow = function (i) {
    return `${parseInt((i) / 3) + 1}行,${parseInt((i) % 3) + 1}列`
}
export {
    calculateWinner,
    showColumnAndRow,
    CalculateWinnerSquareArray
}